import { reqGetGoodsListData } from '@/api';

const state = {
  goodsDetailInfo: {}
};
const actions = {
  // 获取商品详情数据
  async getGoodsListDataActions(context, skuId) {
    const result = await reqGetGoodsListData(skuId);
    if (result.code === 200) {
      context.commit('SAVE_GOODS_LIST_DATA', result.data);
    } else {
      console.log(result.message);
    }
  }
};
const mutations = {
  // 存储商品详情数据
  SAVE_GOODS_LIST_DATA(state, payload) {
    // console.log(payload, '商品详情数据');
    state.goodsDetailInfo = payload;
  },

  // 根据小图更改大图
  UPDATE_SKUINFO_IMGURL(state, imgurl) {
    state.goodsDetailInfo.skuInfo.skuDefaultImg = imgurl
  }
};
const getters = {
  categoryView(state) {
    return state.goodsDetailInfo.categoryView || {};
  },
  skuInfo(state) {
    return state.goodsDetailInfo.skuInfo || {};
  },
  spuSaleAttrList(state) {
    return state.goodsDetailInfo.spuSaleAttrList || {};
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};
